<?php
namespace App\Repositories\Backend;

use App\Models\ComboParameter;
use Illuminate\Support\Facades\Auth;

class ComboParameterRepository extends CommonRepository
{

    public function __construct(ComboParameter $comboparameter)
    {
        parent::__construct($comboparameter);
    }

//    /**
//     * 列表
//     * @param  array $input 查询条件
//     * @return object
//     */
//    public function getLists($input)
//    {
//        $default_search = [
//            'filter' => ['id', 'combos_name', 'combos_now_price', 'combos_ago_price','combos_images1', 'combos_images2', 'order', 'created_at'],
//            'sort'   => [
//                'order' => 'asc',
//            ],
//        ];
//        $search = $this->parseParams($default_search, $input);
//        return $this->model->parseWheres($search)->with('branch', 'parameter')->paginate();
//    }


    /**
     * 新增/修改
     * @param  array  $domains    参数数组
     * @param  int    $combo_id   套餐id
     * @return object
     */
    public function parameter($domains, $combo_id)
    {
        //先删除对应id的数据
        //$result = $this->deleteByWhere(['combo_id'=>$combo_id]);
        $result = $this->model->where('combo_id', $combo_id)->delete();

//        if(!$result){
//            return false;
//        }

        //插入数据
        foreach ($domains as $k=>$v){
            $result = $this->model->create([
                'combo_id' => $combo_id,
                'parameters_key' => $v['parameters_key'],
                'parameters_title' => $v['parameters_title'],
            ]);
        }

        return $result;
    }


}